package com.huawei.classroom.student.h62;

public class MyRemoteFile {
	private MyHost host;
	private String FilePath;
	
//	这个类只是个中转的，实际上还是客户端和服务器在撕逼
	public boolean isDirectory() {
		return host.FileisDirectory(FilePath);
	}
	
	public boolean isFile() {
		return host.FileisFile(FilePath);
	}
//	构造函数，host由于用很多次是同一个，所以不能每次都登录，只能用boolean判断，说白了就是只有一个服务器所以只能一个客户端
	public MyRemoteFile(MyHost host, String FilePath) {
		if(!host.getlogin()) {
			host.logining();
			if(!host.getlogin()) {
				try {
					throw new Exception("login fail");
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		this.host = host;
		this.FilePath = FilePath;	
	}
	
	public MyRemoteFile[] dirByNameAsc() {
		if(!host.getlogin()) {
			try {
				throw new Exception("login fail");
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return host.DisplayFile(FilePath);

	}
	
	public String getPathFileName() {
		return this.FilePath;
	}
	
	public void writeByBytes(byte[] content) {
		host.TowriteByBytes(content, FilePath);
	}
	
	public int length() {
		return host.Tolength(FilePath);
	}
	
	public void delete() {
		host.Todelete(FilePath);
	}
	
	public boolean exists() {
		return host.Toexists(FilePath);
	}
}
